package com.muh.controller;

import com.muh.entity.User1;
import com.muh.service.FeignClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/feignController")
public class FeignController {
    //使用feign面向接口编程
    @Autowired
    private FeignClientService feignClientService;
    //调用feign面向接口中的hello1方法
    @RequestMapping("/getUserById")
    public User1 getUserById(@RequestParam("id") Integer id){
        //调用feign接口中的方法，让feign接口中的方法去调用远程服务的接口（服务提供者的）
        User1 user1 = this.feignClientService.getUserById(id);
        return user1;
    }

    @RequestMapping("/getUserByName")
    public List<User1> getUserByName(@RequestParam("name") String name){
        //调用feign接口中的方法，让feign接口中的方法去调用远程服务的接口（服务提供者的）
        List<User1> user1List = this.feignClientService.getUserByName(name);
        return user1List;
    }

    @RequestMapping(value = "/insert")
    public int insert(@RequestBody User1 user1){
        return this.feignClientService.insert(user1);
    }

    @RequestMapping(value = "/insertBatch")
    public int insertBatch(@RequestBody List<User1> user1List){
        return this.feignClientService.insertBatch(user1List);
    }

    @RequestMapping(value = "/deleteById")
    public boolean deleteById(@RequestParam("id") Integer id){
        return this.feignClientService.deleteById(id);
    }

    @RequestMapping(value = "/update")
    public User1 update(@RequestBody User1 user1){
        return this.feignClientService.update(user1);
    }


    @RequestMapping("/insertOrUpdateBatch")
    public int insertOrUpdateBatch(@RequestBody List<User1> user1List) {
        return this.feignClientService.insertOrUpdateBatch(user1List);
    }
    /******************************************************************************/

    @RequestMapping("/getOnFeign/hello1")
    public String hello1(){
        //调用feign接口中的方法，让feign接口中的方法去调用远程服务的接口（服务提供者的）
        String hello1 = this.feignClientService.hello1();
        return hello1;
    }

    @RequestMapping("/getUserByNameWithCircuitBreaker")
    public List<User1> getUserByNameOnFystrix(@RequestParam("name") String name){
        List<User1> user1List = this.feignClientService.getUserByNameWithCircuitBreaker(name);
        return user1List;
    }


}
